home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group94c.txt / 000042_swampler@noao.edu _Wed Dec 28 11:15:39 1994.msg < prev    next >
Internet Message Format  |  1995-02-09  |  3KB

  1. Received: from optima.CS.Arizona.EDU by cheltenham.CS.Arizona.EDU; Wed, 28 Dec 1994 11:16:08 MST
  2. Received: from noao.edu by optima.CS.Arizona.EDU (5.65c/15) via SMTP
  3.     id AA21060; Wed, 28 Dec 1994 11:16:07 MST
  4. Received: from orpheus.gemini.edu by noao.edu (4.1/SAG-Noao.G96)
  5.     id AA13049; Wed, 28 Dec 94 11:16:05 MST; for icon-group@cs.arizona.edu
  6. Received: by orpheus.gemini.edu (5.0/SMI-SVR4-SAG03X)
  7.     id AA15224; Wed, 28 Dec 1994 11:15:39 +0700
  8. Date: Wed, 28 Dec 1994 11:15:39 +0700
  9. From: swampler@noao.edu
  10. Message-Id: <9412281815.AA15224@orpheus.gemini.edu>
  11. Subject: Re: Truth-Table generator
  12. To: icon-group@cs.arizona.edu
  13. Content-Length: 1800
  14.  
  15. > I had a need to write a program to output truth tables for boolean
  16. > expressions. I used the programmming language J (a sister of APL). The
  17. > 'program' was about two lines long.  I wrote a program for the same task
  18. > in Icon. I include it below.  This Icon solution is ugly (because of the
  19. > programmer, not the language..), but works. I would be happy to hear
  20. > comments. Any idea for improvemnet is welcome.
  21. >
  22. > I got alot of help on comp.lang.apl when writing the J version - so don't
  23. > let me down! I think I will write a short note comparing the solutions.
  24. > My idea is to show the way different languages shape your thought. Both J
  25. > and Icon are rather special in that they give the programmer tools not
  26. > found in other languages. Does this interest anyone?
  27.  
  28. Well, I managed to delete your original program, but here's one that's probably
  29. similar, using generators rather than vectors.  Can it be adapted to your case?
  30.  
  31.    procedure main()
  32.       local t1, t2
  33.  
  34.       every (t1 := (0|1)) & (t2 := (0|1)) do {
  35.          every writes(format ( t1 | t2 |          # variables
  36.                               "|" |              # separator
  37.                               iand(t1,t2) | ior(t1,t2) |  # functions
  38.                               ixor(t1,t2)
  39.                      ))
  40.          write()
  41.          }
  42.  
  43.    end
  44.  
  45.    procedure format(t)
  46.  
  47.       # pretty up things for output, the 'wide' field width (5 characters)
  48.       #   would let this be used to produce a table header, as in:
  49.       #
  50.       #     every writes(format("A" | "B" | "" | "A&B" | "A|B" | "A^B"))
  51.       #     write()
  52.       #
  53.       #   though the above main program doesn't do so...
  54.       # since this is a one-liner, it could be embedded in place of the call
  55.       #   above, but that would be ugly!
  56.  
  57.       return center(map(t, "01", "FT"), 5)
  58.  
  59.    end